package com.android.kotlincoroutinemvvmdemo.view
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import com.android.kotlincoroutinemvvmdemo.R

/*
* TransferDataView
* */
class TransferDataView @JvmOverloads constructor(
    context: Context,
    attributeSet: AttributeSet? = null
) : BaseView(context, attributeSet) {

    private val mPaint0 by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            strokeJoin = Paint.Join.ROUND
            strokeCap = Paint.Cap.ROUND
            strokeWidth = context.resources.getDimension(R.dimen.dp_2)
            color = context.resources.getColor(R.color.color_2979FF)
            style = Paint.Style.FILL_AND_STROKE
        }
    }

    private val mPaint1 by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            color = context.resources.getColor(R.color.color_29FFCD)
            style = Paint.Style.FILL
        }
    }

    private val mPath by lazy {
        Path()
    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        setBackgroundColor(context.resources.getColor(R.color.color_F3F3F3))
        canvas?.apply {
            val cx = mWidth.toFloat() / 2
            val cy = mHeight.toFloat() / 2
            translate(cx, cy)
            drawCircle(0F, 0F, cx, mPaint1)
            val sideWidth = cx / 6
            val baseX = cx / 5
            val baseY = cy * 9 / 20
            mPath.apply {
                reset()
                moveTo(-baseX, -baseY)
                lineTo(-baseX, baseY)
                lineTo(-baseX - sideWidth, baseY - sideWidth)
                lineTo(-baseX, baseY - sideWidth)
            }
            drawPath(mPath, mPaint0)

            mPath.apply {
                reset()
                moveTo(baseX, baseY)
                lineTo(baseX, -baseY)
                lineTo(baseX + sideWidth, -baseY + sideWidth)
                lineTo(baseX, -baseY + sideWidth)
            }
            drawPath(mPath, mPaint0)
        }
    }
}